package com.aaa.controller.systemmanage;

import com.aaa.aspect.LogMonitor;
import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.systemmanage.Dept;
import com.aaa.service.systemmanage.DeptService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 部门表(Dept)表控制层
 *
 * @author makejava
 * @since 2022-08-30 19:45:01
 */
@RestController
@RequestMapping("/dept")
public class DeptController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private DeptService deptService;


    //查询所有
    @RequestMapping(method = RequestMethod.GET, value = "/queryAll.do")
    public Result queryAll(PageSortEntity pageSortEntity, Dept dept) {
        Page pageResult = deptService.queryAll(pageSortEntity, dept);
        return success(pageResult.getResult(), pageResult.getTotal());
    }

    //为下拉框查询所有
    @RequestMapping(method = RequestMethod.POST, value = "/queryAllToSelect.do")
    public Result queryAllToSelect() {
        List<Dept> list = deptService.queryAllToSelect();
        return success(list);
    }

    //添加部门
    @LogMonitor
    @RequestMapping("/insert.do")
    public Result insert(Dept dept) {
        boolean user1 = deptService.insert(dept);
        if (user1) {
            return success();
        } else {
            return fail();
        }
    }

    //删除部门
    @LogMonitor
    @RequestMapping("/delete.do")
    public Result delete(String[] ids) {
        List list = new ArrayList();
        for (String id : ids) {
            list.add(id);
        }
        boolean user1 = deptService.deleteUser(list);
        if (user1) {
            return success();
        } else {
            return fail();
        }
    }

    //修改部门
    @LogMonitor
    @RequestMapping("/update.do")
    public Result update(Dept dept) {
        boolean user1 = deptService.update(dept);
        if (user1) {
            return success();
        } else {
            return fail();
        }
    }


}

